#include <iostream>
#include <boost/thread.hpp>
#include "NetworkController.hpp"

using namespace network;

bool s_run;

void im_with_stupid()
{
    char c;
    while(s_run)
    {
        std::cin >> c;
        if(c=='x')
        {
            s_run = false;
        }
    }
}

int main(void)
{
	char c;
    bool isServer;
    s_run = true;
    std::string str;

    std::cout << "(C) or (S)erver?\n";
	
    std::cin >> c;
    NetworkController& ctrl = NetworkController::getNetworkController();
    if ((c=='c')||(c=='C'))
	{
        isServer = false;
        std::cout << "Enter server IP and hit enter\n";
        std::cin >> str;
        if (str.compare("l")){
	        str = "127.0.0.1";
        }

        Address server(UrlToIp(str),60000);

        ctrl.Connect(server);
	} else {
        isServer = true;

        Address server(0,60000);
        ctrl.Host(server,10);
	}

    boost::thread t(&im_with_stupid);

    while(s_run)
    {
        ctrl.ProcessMessages();
    }

    delete &ctrl;
    return 0;
}